#ifndef INFOPANE_H
#define INFOPANE_H

#include <limits>
#include <logmanager.h>
#include "M_Code_auibook.h"

static const int infopane_flags = wxAUI_NB_MIDDLE_CLICK_CLOSE | wxAUI_NB_WINDOWLIST_BUTTON | wxAUI_NB_SCROLL_BUTTONS
                                  | wxAUI_NB_TAB_MOVE | wxAUI_NB_TAB_SPLIT;
class wxWindow;
class wxCommandEvent;
class wxMouseEvent;

class InfoPane : public M_Code_AuiNotebook {
    DECLARE_EVENT_TABLE()
    struct Page {
      Page() : icon( nullptr ), window( nullptr ), logger( nullptr ), indexInNB( std::numeric_limits<int>::min() ), eventID( 0 ), islogger( 0 ) {};
      wxString  title;
      wxBitmap* icon;
      wxWindow* window;
      Logger* logger;
      int indexInNB;
      int eventID;
      bool islogger;
    };

    typedef int ( *CompareFunction )( Page**, Page** );
    static int  CompareIndexes( Page **p1, Page **p2 );
    void ReorderTabs( CompareFunction cmp_f );
    wxBitmap m_DefaultBitmap;
    WX_DEFINE_ARRAY( Page*, wxArrayOfPage );
    wxArrayOfPage m_Pages;
    void Toggle( size_t index );
    void Hide( size_t i );
    void OnMenu( wxCommandEvent& event );
    void OnCopy( wxCommandEvent& event );
    void OnWrapMode( wxCommandEvent& event );
    void OnClear( wxCommandEvent& event );
    void ContextMenu( wxContextMenuEvent& event );
    void OnTabContextMenu( wxAuiNotebookEvent& event );
    void OnCloseClicked( wxAuiNotebookEvent& event );
    void OnTabPosition( wxCommandEvent& event );
    void DoShowContextMenu();
    int  AddPagePrivate( wxWindow* p, const wxString& title, wxBitmap* icon = nullptr );
    bool InsertPagePrivate( wxWindow* p, const wxString& title, wxBitmap* icon = nullptr, int index = -1 );
    using wxWindow::Show;
  public:
    InfoPane( wxWindow* parent );
    virtual ~InfoPane();
    void Show( size_t index );
    void Show( Logger* logger );
    void Hide( Logger* logger );
    void ShowNonLogger( wxWindow* p );
    void HideNonLogger( wxWindow* p );
    int GetPageIndexByWindow( wxWindow* win );
    int GetCurrentPage( bool &is_logger );
    Logger* GetLogger( int index );
    wxWindow* GetWindow( int index );
    void UpdateEffectiveTabOrder();
    void LoadTabOrder( wxString layout );
    wxString SaveTabOrder();
    bool AddLogger( Logger* logger, wxWindow* p, const wxString& title, wxBitmap* icon = nullptr );
    bool DeleteLogger( Logger* l );
    bool AddNonLogger( wxWindow* p, const wxString& title, wxBitmap* icon = nullptr );
    bool RemoveNonLogger( wxWindow* p );
    bool DeleteNonLogger( wxWindow* p );
};

#endif
